package tx;

import java.util.HashSet;

public class Main {
    public int lengthOfLongestSubstring(String s) {
       int n=s.length();
       int i=0,j=0;
       int maxLen=0;
        HashSet<Character> set=new HashSet<>();
       while (j<n){
           char c=s.charAt(j);
           if (set.contains(c)){
               while (set.contains(c)){
                   set.remove(s.charAt(i));
                   i++;
               }
           }
           set.add(c);
           maxLen=Math.max(maxLen,j-i+1);
           j++;
       }
       return maxLen;
    }
}
